public class LeetCode189 {
    public void rotate1(int[] nums, int k) {
        k = k % nums.length;
        int[] tempArr = new int[k];
        int numLength = nums.length;

        for (int i = numLength - k, ii = 0; i < numLength && ii < k; i++, ii++){
            tempArr[ii] = nums[i];
        }

        for (int j = numLength - k - 1; j >= 0; j--){
            nums[j + k] = nums[j];
        }

        for (int n = 0; n < k; n++){
            nums[n] = tempArr[n];
        }

        for (int x: nums){
            System.out.print(x + " ");
        }
    }
}
